package com.shine.ws.server.conf;

import com.shine.ws.server.interceptor.WebServiceAuthInterceptor;
import com.shine.ws.service.IMessageService;
import javax.annotation.Resource;
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description:
 * @CreateTime: 2023/7/16 22:17
 * @Version:
 * @Since: 1.8
 * @Author: Forward Seen
 */
@Configuration
public class CXFConfig {
    @Resource
    private Bus bus; //注入Bus接口实例
    @Resource
    private IMessageService messageService; //注入业务实例
    @Resource
    private WebServiceAuthInterceptor interceptor; //认证拦截器

    @Bean
    public ServletRegistrationBean getRegistrationBean() {
        return new ServletRegistrationBean(new CXFServlet(), "/services/*");//WebService访问的父路径
    }

    @Bean
    public Endpoint messageEndPoint() {
        EndpointImpl endpoint = new EndpointImpl(this.bus, this.messageService);
        endpoint.publish("/MessageService");
        endpoint.getInInterceptors().add(this.interceptor);//访问拦截器
        return endpoint;
    }
}